


# 1.导包

# 2.准备JSON数据
import jsonschema

json_data = {
    "success": False,
    "code": 10000,
    "message": "xxx登录成功",
    "data": {
        "age": 20,
        "name": "lily"
    }
}
# 3.准备校验规则
schema = {
    "type": "object",
    "required":["success","code","message","data"],
    "properties":{
        "success": {"type": "boolean"},
        "code":{"type": "integer"},
        "message": {"pattern":"登录成功$"},
        "data":{"type":"object",
                "required":["name","age"],
                "properties":{
                    "age" : {"const": 20},
                    "name": {"const":"lily"}
                }
        }
    }
}
# 4.进行校验
jsonschema.validate(json_data,schema)
